const mongoose = require('mongoose')

const url = 'mongodb://localhost:27017'
const dbName = 'myblog'

mongoose.connect(`${url}/${dbName}`, {
    // 配置信息
})

// 获取连接对象
const db = mongoose.connection

// 处理连接错误报错
db.on('error', err => {
    console.error(err)
})

// 连接成功 open 状态
// db.once('open', () => {
//     console.log('mongoose connect success')
// })

module.exports = mongoose
